<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui" >

<ui:composition template="basic-template.xhtml">
	<ui:define name="title"><h:outputText value="Gestione ${crudBean.form.label}"/></ui:define>
	<ui:define  name="content">
		<f:view>
			<h:form id="crudForm">
				<p:panel id="crudPanel">
					<f:facet name="header">
						<span class="headerTitle"><h:outputText value="Gestione ${crudBean.form.label}"/></span>
							<span class="headerButton">
								<p:commandButton styleClass="pulsante-icon"  
												 actionListener="#{crudBean.doNew}"
												 icon="ui-icon-aggiungi" 
												 title="Crea nuovo "
												 oncomplete="crudFormDialogWidget.show()" 
												 update=":crudFormPanel">
									<p:resetInput target=":crudFormPanel"></p:resetInput>
								</p:commandButton>
							</span>
					</f:facet>
	  				<p:dataTable var="item" 
	  							 id="crudTable" 
	  							 value="#{crudBean.values}" 
	  							 widgetVar="crudTableWidget"
								 styleClass="tabellaElenco"
								 rowKey="#{item.id}">
						<p:column>
							<p:commandButton styleClass="pulsante-icon" 
									 action="#{crudBean.doEdit}"
									 icon="ui-icon-aggiorna" 
									 title="Aggiorna "
									 oncomplete="crudFormDialogWidget.show()"
									 id="aggiorna1"
									 update=":crudFormPanel,:messages">
								<f:setPropertyActionListener for="aggiorna1" target="#{crudBean.id}" value="#{item.id}" />
								<p:resetInput target=":crudFormPanel"></p:resetInput>
							</p:commandButton>
							<ui:insert name="custombuttons"></ui:insert>
						</p:column>
						<p:columns value="#{crudBean.form.properties}" 
								   var="column" 
								   columnIndexVar="colIndex"   
	                    		   sortBy="#{column.name}" 
	                    		   filterBy="#{column.name}">  
				            <f:facet name="header">  
				                #{column.label}  
				            </f:facet>  
				            	<h:outputText value="#{item[column.name]}" rendered="#{column.type=='STRING'}"/>
				            	<h:outputText value="#{item[column.name]}" rendered="#{column.type=='TIMESTAMP'}">
				            		<f:convertDateTime pattern="dd-MM-yyyy HH:mm:ss" locale="it_IT"/>
				            	</h:outputText>

								<ui:repeat var="x" value="#{item[column.name]}" rendered="#{column.type=='SET'}">
									<h:outputText value="#{x.labelSearch}" />
								</ui:repeat>				            	
				              
	        			</p:columns>
	
					</p:dataTable>
				</p:panel>
			</h:form>

			<p:dialog   id="crudFormDialog" 
						styleClass="dialogUpdate"
						header="Gestione ${crudBean.form.label}"
						modal="true"  
						widgetVar="crudFormDialogWidget">
				<p:panel id="crudFormPanel">
					<h:form id="crudFormFields">

	  				<p:dataTable var="p" 
	  							 id="crudTable" 
	  							 value="#{crudBean.form.properties}" 
	  							 widgetVar="crudTableWidget"
								 styleClass="tabellaElenco"
								 rowKey="#{p.name}" rendered="#{! empty crudBean.row}">
	
						<p:column>${p.name}</p:column>
						<p:column>
							<p:inputText label="${p.label}"
								value="${crudBean.row.values[p.name]}"
								maxlength="${p.length}"
								required="${p.nullable?'false':'true'}"
								size="${p.length>80?80:p.length}" 
								rendered="#{p.type=='STRING'}" >
								<f:attribute name="customvalidator" value="${p.validator}"></f:attribute>
								<f:validator validatorId="crudvalidator" />
							</p:inputText>
								
							<p:calendar 
								value="${crudBean.row.values[p.name]}"
								rendered="#{p.type=='TIMESTAMP'}"
								/>
							<p:autoComplete value="${crudBean.row.values[p.name]}"   
                        					id="basicPojo"
                        					completeMethod="#{crudBean.selectorsJsfBean[p.subtype].complete}"
                        					  
                        					var="v" multiple="true"
                        					itemLabel="#{v.labelSearch}" 
                        					itemValue="#{v}" 
                        					converter="${rowConverter}" 
                        					rendered="#{p.type=='SET'}" >
                        	</p:autoComplete>  
							<p:inputTextarea value="${crudBean.row.values[p.name]}"
											cols="80"
											rows="5"
											   
                        					rendered="#{p.type=='TEXT'}" >
                        	</p:inputTextarea>  


						</p:column>
	
						<f:facet name="footer">
								<p:column colspan="2">
								<p:commandButton styleClass="pulsante-save" 
									value="#{CRUDBean.insertMode?'Inserisci':'Aggiorna'}" type="submit"
									actionListener="#{crudBean.doSave}"
									oncomplete="handleSaveRequest(xhr, status, args)"
									update=":messages,:crudFormPanel,:crudForm">
								</p:commandButton> 
								<p:commandButton styleClass="pulsante-delete" 
									value="elimina" type="submit"
									rendered="#{! crudBean.insertMode}"
									onclick="crudFormConfirmationWidget.show()">
								</p:commandButton>
								</p:column>
						
						</f:facet>
					</p:dataTable>


	     			</h:form>
	     		</p:panel>
	     	</p:dialog>


			<p:dialog id="crudFormConfirmation" 
						  styleClass="dialogUpdateConfirmation"
						  header="Cancellazione "
						  modal="true" appendToBody="true" 
						  widgetVar="crudFormConfirmationWidget">
					<h:outputText value="Cancellazione "/>
					<h:form>
				        <p:commandButton value="Yes" 
				        	type="submit"  
							actionListener="#{crudBean.doDelete}"
							onclick="crudFormConfirmationWidget.hide()"
								oncomplete="handleSaveRequest(xhr, status, args)"
							update=":messages,:crudFormPanel,:crudForm"
					        styleClass="ui-confirmdialog-yes" icon="ui-icon-check"/>  
				        <p:commandButton value="No" 
				        				 type="button" 
				        				 styleClass="ui-confirmdialog-no" icon="ui-icon-close"
				        				 onclick="crudFormConfirmationWidget.hide()"
				        				 />       
					</h:form>
				</p:dialog>  


		</f:view>





	</ui:define>
</ui:composition>
</html>
